import 'package:flutter/material.dart';
import 'package:get/get.dart';

/// todo: 通用顶部导航
appBarWidget({
  String? title,
  bool? centerTitle,
  List<Widget>? actions,
  double? elevation,
  Widget? leading,
  double? titleSize,
  Color? backgroundColor,
  Color? leftColor,
  Color? titleColor,
}) {
  return AppBar(
    leading: leading ??
        InkWell(
          child: Icon(
            Icons.chevron_left,
            color: leftColor,
            size: 30,
          ),
          onTap: () => Get.back(),
        ),
    title: Text(
      title ?? '',
      style: TextStyle(
        fontSize: titleSize ?? 16,
        color: titleColor ?? Colors.black,
      ),
    ),
    centerTitle: centerTitle ?? true,
    actions: actions,
    elevation: elevation ?? 0.5,
    backgroundColor: backgroundColor,
  );
}

/// todo：可用于任意场景的顶部导航
appBarRowWidget({
  double? width,
  double? height,
  Widget? left,
  Widget? right,
  double? titleSize,
  String? title,
  Color? backgroundColor,
}) {
  return SafeArea(child: Container(
    width: width,
    height: height ?? 45,
    color: backgroundColor ?? Colors.white,
    padding: EdgeInsets.symmetric(
      horizontal: 12,
    ),
    child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Container(
          alignment: Alignment.centerLeft,
          child: left ??
              InkWell(
                child: Icon(
                  Icons.chevron_left,
                  size: 30,
                ),
                onTap: () {
                  Get.back();
                },
              ),
        ),
        Expanded(
          child: Center(
            child: Text(
              title ?? '',
              style: TextStyle(
                fontWeight: FontWeight.w500,
                fontSize: titleSize ?? 16,
              ),
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
            ),
          ),
        ),
        Container(
          alignment: Alignment.centerRight,
          child: right,
        ),
      ],
    ),
  ));
}
